package com.hzlx.reports.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.reports.domain.NonConformingReports;
import com.hzlx.reports.service.INonConformingReportsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 不合格品报告（NCR）管理（记录从发现到关闭的全过程）Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/quality")
public class NonConformingReportsController extends BaseController
{
    @Autowired
    private INonConformingReportsService nonConformingReportsService;

    /**
     * 查询不合格品报告（NCR）管理（记录从发现到关闭的全过程）列表
     */
    @RequiresPermissions("quality-service:reports:list")
    @GetMapping("/reports/list")
    public TableDataInfo list(NonConformingReports nonConformingReports)
    {
        startPage();
        List<NonConformingReports> list = nonConformingReportsService.selectNonConformingReportsList(nonConformingReports);
        return getDataTable(list);
    }

    /**
     * 导出不合格品报告（NCR）管理（记录从发现到关闭的全过程）列表
     */
    @RequiresPermissions("quality-service:reports:export")
    @Log(title = "不合格品报告（NCR）管理（记录从发现到关闭的全过程）", businessType = BusinessType.EXPORT)
    @PostMapping("/reports/export")
    public void export(HttpServletResponse response, NonConformingReports nonConformingReports)
    {
        List<NonConformingReports> list = nonConformingReportsService.selectNonConformingReportsList(nonConformingReports);
        ExcelUtil<NonConformingReports> util = new ExcelUtil<NonConformingReports>(NonConformingReports.class);
        util.exportExcel(response, list, "不合格品报告（NCR）管理（记录从发现到关闭的全过程）数据");
    }

    /**
     * 获取不合格品报告（NCR）管理（记录从发现到关闭的全过程）详细信息
     */
    @RequiresPermissions("quality-service:reports:query")
    @GetMapping(value = "/reports/{ncrId}")
    public AjaxResult getInfo(@PathVariable("ncrId") String ncrId)
    {
        return success(nonConformingReportsService.selectNonConformingReportsByNcrId(ncrId));
    }

    /**
     * 新增不合格品报告（NCR）管理（记录从发现到关闭的全过程）
     */
    @RequiresPermissions("quality-service:reports:add")
    @Log(title = "不合格品报告（NCR）管理（记录从发现到关闭的全过程）", businessType = BusinessType.INSERT)
    @PostMapping("/reports")
    public AjaxResult add(@RequestBody NonConformingReports nonConformingReports)
    {
        return toAjax(nonConformingReportsService.insertNonConformingReports(nonConformingReports));
    }

    /**
     * 修改不合格品报告（NCR）管理（记录从发现到关闭的全过程）
     */
    @RequiresPermissions("quality-service:reports:edit")
    @Log(title = "不合格品报告（NCR）管理（记录从发现到关闭的全过程）", businessType = BusinessType.UPDATE)
    @PutMapping("/reports")
    public AjaxResult edit(@RequestBody NonConformingReports nonConformingReports)
    {
        return toAjax(nonConformingReportsService.updateNonConformingReports(nonConformingReports));
    }

    /**
     * 删除不合格品报告（NCR）管理（记录从发现到关闭的全过程）
     */
    @RequiresPermissions("quality-service:reports:remove")
    @Log(title = "不合格品报告（NCR）管理（记录从发现到关闭的全过程）", businessType = BusinessType.DELETE)
	@DeleteMapping("/reports/{ncrIds}")
    public AjaxResult remove(@PathVariable String[] ncrIds)
    {
        return toAjax(nonConformingReportsService.deleteNonConformingReportsByNcrIds(ncrIds));
    }
}
